﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using MVCProject.Model;
using MVCProject.BLL;

namespace MVCProject.API.Controllers
{
    public class DepartmentsController : ApiController
    {
        // GET: api/Departments
        public List<DepartmentsDto> Get()
        {
            DepartmentBll bll = new DepartmentBll();

            var data = bll.Query();

            var list = from d in data
                       select new DepartmentsDto() { 
                           DeptID= d.deptID,
                           DeptName= d.deptName,
                           Remark = d.remark
                       };

            return list.ToList();
        }

        // GET: api/Departments/5
        public string Get(int id)
        {
            return "value";
        }

        // POST: api/Departments
        public Result Post([FromBody]DepartmentsDto value)
        {
            Department dd = new Department();
            dd.deptID = value.DeptID;
            dd.deptName= value.DeptName;
            dd.remark = value.Remark;

            var bol = new DepartmentBll().Add(dd);


            Result result = new Result();
            result.code = bol ? 1 : 0;
            result.msg = bol ? "ok" : "error";
            return result;
        }

        // PUT: api/Departments/5
        public void Put(int id, [FromBody]string value)
        {
        }

        // DELETE: api/Departments/5
        public void Delete(int id)
        {
        }
    }
}
